<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('operation_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->nullable()->comment('用户ID');
            $table->string('username')->nullable()->comment('用户名');
            $table->string('method')->comment('请求方法');
            $table->string('path')->comment('请求路径');
            $table->text('params')->nullable()->comment('请求参数');
            $table->string('ip')->nullable()->comment('IP地址');
            $table->text('user_agent')->nullable()->comment('用户代理');
            $table->string('status')->default('success')->comment('操作状态');
            $table->text('message')->nullable()->comment('操作消息');
            $table->timestamp('created_at')->useCurrent();

            $table->index('user_id');
            $table->index('created_at');
            $table->index('path');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('operation_logs');
    }
};

